package com.thoughtworks.turtlemock;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Understands how to publish message to its subscribers
 * @author taowen
 *
 */
public class Publisher {
	
	private Set subscribers = new HashSet();

	public void add(Subscriber subscriber) {
		subscribers.add(subscriber);
	}

	public void publish(String message) {
		Iterator iterator = subscribers.iterator();
		while (iterator.hasNext()) {
			Subscriber subscriber = (Subscriber) iterator.next();
			subscriber.receive(message);
		}
	}
}
